package com.zhida84.Impl;
/**
 * 
 * @author shazhengbo sunchangxing
 *
 */
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.zhida84.Dao.DBSQL;
import com.zhida84.Dao.UserDao;
import com.zhida84.Entity.UserTab;

public class UserImpl implements UserDao {
	DBSQL db = new DBSQL();

	@Override
	public ResultSet valPhone(String phone) {
		String strQuery = "select * from usertable where userPhone=?";
		return db.getQuery(strQuery, new Object[] { phone });
	}

	@Override
	public int RegistUser(UserTab user) {
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		String strQUery = "insert into usertable (userPhone,userPwd,school,userRgDate) value(?,?,?,?)";
		return db.getUpdate(
				strQUery,
				new Object[] { user.getUserPhone(), user.getUserPwd(),
						user.getSchool(), time.format(new Date()) });
	}

	@Override
	public ResultSet valUserTab(UserTab user) {
		String strQuery = "select * from usertable where userPhone=? and userPwd=?";
		return db.getQuery(strQuery,
				new Object[] { user.getUserPhone(), user.getUserPwd() });
	}

	@Override
	public int changePwd(UserTab user) {
		String strQuery = "Update usertable set userPwd=? where userPhone=?";
		return db.getUpdate(strQuery,
				new Object[] { user.getUserPwd(), user.getUserPhone() });
	}

	@Override
	public ResultSet personal(int nid) {
		String strQuery = "Select * from usertable WHERE userId=?";
		return db.getQuery(strQuery, new Object[] { nid });
	}

	@Override
	public int chpersonal(UserTab userTB) {
		String strQuery = "update usertable set userReName=?,userAge=?,userSex=?,qqwc=?,school=?,description=?,major=?,hopeJob=?  where  userPhone=?";
		return db.getUpdate(strQuery, new Object[] { userTB.getUserReName(),
				userTB.getUserAge(), userTB.getUserSex(), userTB.getQqwc(),
				userTB.getSchool(), userTB.getDescription(), userTB.getMajor(),
				userTB.getHopeJob(), userTB.getUserPhone() });
	}
	@Override
	public ResultSet getZFB(String phone) {
			String  sql="select * from usertable where userPhone=?"; 
			return db.getQuery(sql, new Object[]{phone});
	}

	@Override
	public int UpdateZFB(String ReName, String alipay, String phone) {
		String sql="update usertable set userReName=?,alipay=? where userPhone=?";
		return db.getUpdate(sql, new Object[]{ReName,alipay,phone});
	}

}
